package com.tvein.sanguo.action.controller.role
{
	//flash
	//pureMVC
	import flash.display.DisplayObject;
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.action.common.GameConstants;
	import com.tvein.sanguo.action.view.ActionMediator;
	import com.tvein.sanguo.action.model.SystemProxy;
	import com.tvein.sanguo.swc.action.role.RoleList;
	import com.tvein.sanguo.swc.action.role.RoleCreate;
	import com.tvein.sanguo.swc.action.role.RoleDelete;
	import com.tvein.sanguo.swc.action.role.RoleDetail;
	import com.tvein.sanguo.swc.action.role.RoleArmy;
	import com.tvein.sanguo.swc.action.role.RoleGoods;
	import com.tvein.sanguo.swc.action.role.RoleItem;
	import com.tvein.sanguo.swc.action.role.RoleItemInfo;
	import com.tvein.sanguo.swc.action.role.RoleSkill;
//
	public class ActionRole extends SimpleFabricationCommand implements ICommand
	{
		private var actionMediator:ActionMediator;
		private var systemData:SystemProxy;
		
		override public function execute(notification:INotification) : void
		{
			actionMediator = facade.retrieveMediator(ActionMediator.NAME) as ActionMediator;
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			clearChild();
			
			var params:Object = new Object();
			
			switch(notification.getBody()[0])
			{
				case "roleCreate":
					var roleCreate:RoleCreate = new RoleCreate();
					actionMediator.action.addChild(roleCreate);
					roleCreate.name = "RoleCreate";
					
					params.Address = systemData.srcServer;
					roleCreate.console("setSource", params);
					params.Volume = systemData.effectVol;
					roleCreate.console("setEffect", params);
					
					routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", "GetGameData(Action,GetImageArea)"], null, "*");
					
					roleCreate.addEventListener("Role-Create", actionMediator._handleEvents);
					
					break;
				case "roleDelete":
					var roleDelete:RoleDelete = new RoleDelete();
					actionMediator.action.addChild(roleDelete);
					roleDelete.name = "RoleDelete";
					
					params.Address = systemData.srcServer;
					roleDelete.console("setSource", params);
					params.Volume = systemData.effectVol;
					roleDelete.console("setEffect", params);
					
					roleDelete.console("setData", notification.getBody()[1]);
					roleDelete.addEventListener("Role-Delete", actionMediator._handleEvents);
					
					break;
				case "roleDetail":
					var roleDetail:RoleDetail = new RoleDetail();
					actionMediator.action.addChild(roleDetail);
					roleDetail.name = "RoleDetail";
					
					params.Address = systemData.srcServer;
					roleDetail.console("setSource", params);
					params.Volume = systemData.effectVol;
					roleDetail.console("setEffect", params);
					
					routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", "GetGameData(Action,GetRoleDetail)"], null, "*");
					
					roleDetail.addEventListener("Role-Detail", actionMediator._handleEvents);
					
					break;
				case "roleGoods":
					var roleGoods:RoleGoods = new RoleGoods();
					actionMediator.action.addChild(roleGoods);
					roleGoods.name = "RoleGoods";
					
					params.Volume = systemData.effectVol;
					roleGoods.console("setEffect", params);
					
					routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", "GetGameData(Action,GetRoleGoods)"], null, "*");
					
					roleGoods.addEventListener("Role-Goods", actionMediator._handleEvents);
					
					break;
				case "roleItem":
					var roleItem:RoleItem = new RoleItem();
					actionMediator.action.addChild(roleItem);
					roleItem.name = "RoleItem";
					
					params.Volume = systemData.effectVol;
					roleItem.console("setEffect", params);
					
					routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", "GetGameData(Action,GetRoleItem)"], null, "*");
					
					roleItem.addEventListener("Role-Item", actionMediator._handleEvents);
					
					break;
				case "roleItemInfo":
					var roleItemInfo:RoleItemInfo = new RoleItemInfo();
					actionMediator.action.addChild(roleItemInfo);
					roleItemInfo.name = "RoleItemInfo";
					
					params.Address = systemData.srcServer;
					roleItemInfo.console("setSource", params);
					params.Volume = systemData.effectVol;
					roleItemInfo.console("setEffect", params);
					
					routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", "GetGameData(Action,GetRoleItemInfo," + notification.getBody()[1] + "," + notification.getBody()[2] + ")"], null, "*");
					
					roleItemInfo.addEventListener("Role-ItemInfo", actionMediator._handleEvents);
					
					break;
				case "roleSkill":
					var roleSkill:RoleSkill = new RoleSkill();
					actionMediator.action.addChild(roleSkill);
					roleSkill.name = "RoleSkill";
					
					params.Volume = systemData.effectVol;
					roleSkill.console("setEffect", params);
					
					routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", "GetGameData(Action,GetRoleSkill)"], null, "*");
					
					roleSkill.addEventListener("Role-Skill", actionMediator._handleEvents);
					
					break;
				case "roleArmy":
					/*
					var roleArmy:RoleArmy = new RoleArmy();
					actionMediator.action.addChild(roleArmy);
					roleArmy.name = "RoleArmy";
					
					params.Volume = systemData.effectVol;
					roleArmy.console("setEffect", params);
					
					roleArmy.console("setData", notification.getBody()[1]);
					roleArmy.addEventListener("Role-Army", actionMediator._handleEvents);
					*/
					break;
			}
		}
		
		private function clearChild():void
		{
			for (var i:int = actionMediator.action.numChildren - 1; i >= 0; i--)
			{
				actionMediator.action.removeChildAt(0); 
			}
		}
	}
}